/*************************************************************************
	Layer Inspector
	
*************************************************************************/

using UnityEditor;
using UnityEngine;
using System.Collections;
	
[CustomEditor(typeof(UTVPLayer))]
public class UTVPLayerInspector : Editor {

	public override void OnInspectorGUI () {
		serializedObject.Update ();
		
		UTVPLayer layer = (UTVPLayer)target;
		
		//DrawDefaultInspector();
		
		//EditorGUIUtility.LookLikeInspector();
		GUILayout.BeginHorizontal();
		Texture2D imageTemp = (Texture2D)EditorGUILayout.ObjectField("Image", layer.Image != null ? layer.Image.tex : null, typeof(Texture2D), false);
		if (layer.Image == null || layer.Image.tex != imageTemp)
		{
			if (imageTemp != null)
				layer.Image = layer.Storages.GetImage(imageTemp.name);
			else
				layer.Image = null;
		}
		if(GUILayout.Button("Resize")) {
			if (imageTemp != null)
				layer.SetSizeToImageSize();
			else if (layer.IsPrimary)
			{
				layer.Visible = true;
				layer.Image = null;
				layer.SetPosAndSize(0, 0, layer.System.Width, layer.System.Height);
			}
		}
		GUILayout.EndHorizontal();
		EditorGUIUtility.LookLikeControls();
		layer.UseSharedMaterial = EditorGUILayout.Toggle("UseSharedMaterial", layer.UseSharedMaterial);
		layer.Visible = EditorGUILayout.Toggle("Visible", layer.Visible);
		layer.Left = EditorGUILayout.IntField("Left", layer.Left);
		layer.Top = EditorGUILayout.IntField("Top", layer.Top);
		layer.Width = EditorGUILayout.IntField("Width", layer.Width);
		layer.Height = EditorGUILayout.IntField("Height", layer.Height);
		layer.ImageLeft = EditorGUILayout.IntField("ImageLeft", layer.ImageLeft);
		layer.ImageTop = EditorGUILayout.IntField("ImageTop", layer.ImageTop);
		layer.ImageWidth = EditorGUILayout.IntField("ImageWidth", layer.ImageWidth);
		layer.ImageHeight = EditorGUILayout.IntField("ImageHeight", layer.ImageHeight);
		EditorGUILayout.LabelField("TextureWidth", "" + layer.TexWidth);
		EditorGUILayout.LabelField("TextureHeight", "" + layer.TexHeight);
		layer.Slice9Left = EditorGUILayout.IntField("9SliceLeft", layer.Slice9Left);
		layer.Slice9Top = EditorGUILayout.IntField("9SliceTop", layer.Slice9Top);
		layer.Slice9Right = EditorGUILayout.IntField("9SliceRight", layer.Slice9Right);
		layer.Slice9Bottom = EditorGUILayout.IntField("9SliceBottom", layer.Slice9Bottom);
		layer.AbsoluteIndex = EditorGUILayout.IntField("AbsoluteIndex", layer.AbsoluteIndex);
		layer.Color = EditorGUILayout.ColorField("Color", layer.Color);
		layer.FlipLR = EditorGUILayout.Toggle("FlipLR", layer.FlipLR);
		layer.FlipUD = EditorGUILayout.Toggle("FlipUD", layer.FlipUD);
		layer.ClipWithinParent = EditorGUILayout.Toggle("ClipWithinParent", layer.ClipWithinParent);
		EditorGUILayout.LabelField("CursorX", "" + layer.CursorX);
		EditorGUILayout.LabelField("CursorY", "" + layer.CursorY);
		layer.HitType = (UTVPLayer.HIT_TYPE)EditorGUILayout.EnumPopup("HitType", layer.HitType);
		if(layer.HitType == UTVPLayer.HIT_TYPE.IMAGE)
			layer.HitThreshold = EditorGUILayout.IntField("HitThreshold", layer.HitThreshold);
		EditorGUILayout.Toggle("IsPrimary", layer.IsPrimary);
	}
}
